#ifndef PROCESS_H
#define PROCESS_H

#include <QProcess>
#include <QVariant>

class Process : public QProcess
{
    Q_OBJECT

    Q_PROPERTY(QString applicationDirPath READ applicationDirPath NOTIFY never)
    Q_PROPERTY(QString workingDirectory WRITE setWorkingDirectory READ workingDirectory NOTIFY never)
    Q_PROPERTY(bool isRunning READ isRunning NOTIFY isRunningChanged)

public:
    Process(QObject *parent = 0);

    ~Process();

    Q_INVOKABLE void start(const QString &program, const QVariantList &arguments);

    Q_INVOKABLE QString applicationDirPath();

    bool isRunning();

signals:
    Q_INVOKABLE void outputRead(QString output);
    Q_INVOKABLE void finished(int code);
    Q_INVOKABLE void never();
    void isRunningChanged(bool isRunning);

private slots:
    void onReadyRead();
    void onFinished(int code, QProcess::ExitStatus status);
    void onStateChanged(QProcess::ProcessState state);

private:
    bool wasRunning = false;
};

#endif // PROCESS_H
